home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 6.0 KB | 203 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- package mixer.display;
-
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
-
- import quicktime.*;
- import quicktime.app.audio.*;
- import quicktime.std.music.*;
- import quicktime.std.*;
- import quicktime.std.movies.*;
-
- import mixer.mc.*;
-
- /** This class is a special display (not extending ChannelDisplay) that provides the
- * controls specifically suited for a music part. It also uses a different layout
- * format than the ChannelDisplay.
- */
- public class MusicPartDisplay extends JPanel implements StdQTConstants {
- private MixerComponents[] parts;
- private static final int VOLUME_WIDTH = 80;
- private static final int VOLUME_HEIGHT = 20;
- private static final int BALANCE_WIDTH = 60;
- private static final int BALANCE_HEIGHT = 20;
-
- /** The constructor needs an array of MixerMusicPart objects that it is creating the
- * control panel for. It will create a mixer for each entry in the array.
- * @param the MixerComponents [] to make the display for
- */
- public MusicPartDisplay (Movie m, MixerComponents[] musicParts) throws QTException {
- super();
- parts = musicParts;
-
- setLayout(new GridBagLayout());
- buildMusicControl(m);
- }
-
- /* This method goes through the work of creating a control panel entry for each
- * channel.
- */
- private void buildMusicControl (Movie m) throws QTException {
- int numParts = parts.length;
- GridBagConstraints cons = new GridBagConstraints();
- cons.gridx = GridBagConstraints.RELATIVE;
- cons.gridy = 0;
- cons.gridwidth = 1;
- cons.gridheight = 1;
- cons.weightx = 0.0F;
- cons.weighty = 0.0F;
-
- add(new Label("Instrument"), cons);
- add(new Label("Volume"), cons);
- add(new Label("Balance"), cons);
- add(new Label("Mute"), cons);
-
- for (int i = 0; i < numParts; i++) {
- cons.gridy = i + 1;
- cons.fill = GridBagConstraints.HORIZONTAL;
-
- MusicPart mpc = (MusicPart)parts[i].getMaster();
- addInstrumentButton (m, cons, mpc);
-
- cons.fill = GridBagConstraints.NONE;
- addVolumeSlider (cons, mpc);
- addBalanceSlider (cons, mpc);
- addMuteButton (cons, mpc);
- }
- }
-
- /* This is what has to happen to add an Instrument Choosing button for a channel. */
- private void addInstrumentButton (Movie m, Object cons, MusicPart c) throws QTException{
- JButton instrument = new JButton(c.getInstrumentName());
- add(instrument, cons);
-
- InstrumentListener l = new InstrumentListener(m, c);
- instrument.addActionListener(l);
- }
-
- /* This is what has to happen to add a Volume Slider for a channel. */
- private void addVolumeSlider (Object cons, MusicPart c) throws QTException {
- JSlider volume = new JSlider(JSlider.HORIZONTAL, 0, 128, 100);
- volume.setPreferredSize(new Dimension(VOLUME_WIDTH, VOLUME_HEIGHT));
- volume.setMinimumSize(new Dimension(VOLUME_WIDTH, VOLUME_HEIGHT));
- add (volume, cons);
-
- VolumeListener l = new VolumeListener(c);
- volume.addChangeListener(l);
- volume.setValue((int)(128.0F * c.getVolume()));
- }
-
- /* This is what has to happen to add a Balance Slider for a channel. */
- private void addBalanceSlider (Object cons, MusicPart c) throws QTException {
- JSlider balance = new JSlider(JSlider.HORIZONTAL, -127, 127, 0);
- balance.setPreferredSize(new Dimension(BALANCE_WIDTH, BALANCE_HEIGHT));
- balance.setMinimumSize(new Dimension(BALANCE_WIDTH, BALANCE_HEIGHT));
- add(balance, cons);
-
- BalanceListener l = new BalanceListener(c);
- balance.addChangeListener(l);
- balance.setValue((int)(127.0F * c.getBalance()));
- }
-
- /* This is what has to happen to add a Mute Button for a channel. */
- private void addMuteButton (Object cons, MusicPart c) throws QTException {
- JCheckBox mute = new JCheckBox();
- add(mute, cons);
-
- MuteListener l = new MuteListener(c);
- mute.addActionListener(l);
- mute.setSelected(c.isMuted());
- }
-
- /* The following inner classes are the listeners for the instrument button, volume
- * slider, and balance slider. Notice that each one takes a MusicPart object
- * in the constructor so that it know which channel it's acting upon.
- */
- class InstrumentListener implements ActionListener {
- private MusicPart part;
- private Movie mov;
-
- public InstrumentListener (Movie m, MusicPart c) {
- part = c;
- mov = m;
- }
-
- public void actionPerformed(ActionEvent e) {
- try {
- if (mov != null) {
- part.getNoteChannel().pickEditInstrument("Choose instrument...", kPickEditAllowPick);
- } else
- part.selectInstrument("Choose instrument...");
- ((JButton) e.getSource()).setText(part.getInstrumentName());
- }
- catch (QTException ex) {
- if (-128 != ex.errorCode()) { // deals with the "user cancelled" case
- ex.printStackTrace();
- }
- }
- }
- }
-
- class VolumeListener implements ChangeListener {
- private MusicPart part;
-
- public VolumeListener (MusicPart c) {
- part = c;
- }
-
- public void stateChanged(ChangeEvent e) {
- try {
- Integer tmp = new Integer(((JSlider) e.getSource()).getValue());
- part.setVolume (tmp.floatValue() / 128.0F);
- }
- catch (QTException ex) {
- ex.printStackTrace();
- }
- }
- }
-
- class BalanceListener implements ChangeListener {
- private MusicPart part;
-
- public BalanceListener(MusicPart c) {
- part = c;
- }
-
- public void stateChanged(ChangeEvent e) {
- try {
- Integer b = new Integer(((JSlider) e.getSource()).getValue());
- part.setBalance (b.floatValue() / 127.0F);
- }
- catch (QTException ex) {
- ex.printStackTrace();
- }
- }
- }
-
- class MuteListener implements ActionListener {
- private MusicPart part;
-
- public MuteListener(MusicPart c) {
- part = c;
- }
-
- public void actionPerformed(ActionEvent e) {
- try {
- JCheckBox source = (JCheckBox) e.getSource();
- part.setMuted(source.isSelected());
- }
- catch (QTException ex) {
- ex.printStackTrace();
- }
- }
- }
- }